﻿using Cinema.Model.EF.Repositories;
using Cinema.Model.Entities;
using Cinema.Model.Interfaces;

namespace Cinema.Model.EF
{
    public class UnitOfWork : IUnitOfWork
    {
        protected CinemaContext _cinemaContext = new CinemaContext();

        private IRepository<Actor> _actorRepository;
        public IRepository<Actor> ActorRepository
        {
            get 
            {
                if (_actorRepository == null)
                    _actorRepository = new ActorRepository(_cinemaContext);

                return _actorRepository;
            }
        }

        private IRepository<Genre> _genreRepository;
        public IRepository<Genre> GenreRepository
        {
            get
            {
                if (_genreRepository == null)
                    _genreRepository = new GenreRepository(_cinemaContext);

                return _genreRepository;
            }
        }

        private IRepository<Movie> _movieRepository;
        public IRepository<Movie> MovieRepository
        {
            get
            {
                if (_movieRepository == null)
                    _movieRepository = new MovieRepository(_cinemaContext);

                return _movieRepository;
            }
        }

        private IRepository<MovieType> _movieTypeRepository;
        public IRepository<MovieType> MovieTypeRepository
        {
            get
            {
                if (_movieTypeRepository == null)
                    _movieTypeRepository = new MovieTypeRepository(_cinemaContext);

                return _movieTypeRepository;
            }
        }

        private IRepository<Projection> _projectionRepository;
        public IRepository<Projection> ProjectionRepository
        {
            get
            {
                if (_projectionRepository == null)
                    _projectionRepository = new ProjectionRepository(_cinemaContext);

                return _projectionRepository;
            }
        }

        private IRepository<Reservation> _reservationRepository;
        public IRepository<Reservation> ReservationRepository
        {
            get
            {
                if (_reservationRepository == null)
                    _reservationRepository = new ReservationRepository(_cinemaContext);

                return _reservationRepository;
            }
        }

        private IRepository<Room> _roomRepository;
        public IRepository<Room> RoomRepository
        {
            get
            {
                if (_roomRepository == null)
                    _roomRepository = new RoomRepository(_cinemaContext);

                return _roomRepository;
            }
        }

        private IRepository<User> _userRepository;
        public IRepository<User> UserRepository
        {
            get
            {
                if (_userRepository == null)
                    _userRepository = new UserRepository(_cinemaContext);

                return _userRepository;
            }
        }

        public void SaveChanges()
        {
            _cinemaContext.SaveChanges();
        }
    }
}
